package com.digital.smartgrow.controller.process;

import com.digital.smartgrow.common.advice.Result;
import com.digital.smartgrow.dto.process.UpProcessPageDTO;
import com.digital.smartgrow.entity.process.UpProcess;
import com.digital.smartgrow.service.process.UpProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 审批流
 前端控制器
 * </p>
 *
 * @author sunyuechao
 * @since 2022-07-13
 */
@Api(tags = "审批流 ")
@RestController
@RequestMapping("${context.prefix}/syc/upProcess")
public class UpProcessController {

    @Autowired
    private UpProcessService upProcessService;

    @ApiOperation(value = "审批流 -分页查询")
    @PostMapping("/list")
    public Object getListByPage(@RequestBody UpProcessPageDTO upProcessPageDTO){
        return upProcessService.getListByPage(upProcessPageDTO);
    }

    @ApiOperation(value = "审批流 -详情")
    @GetMapping("/{id}")
    public Object getInfo(@PathVariable Integer id){
        if (id == null) return Result.fail("id不能为空");
        return upProcessService.getInfo(id);
    }

    @ApiOperation(value = "审批流 -删除")
    @DeleteMapping("/{id}")
    public Object removeById(@PathVariable Integer id){
      if (id == null) return Result.fail("id不能为空");
      return upProcessService.removeById(id);
    }
    @ApiOperation(value = "审批流 -新增")
    @PostMapping()
    public Object add( @RequestBody UpProcess upProcess){
        upProcessService.save(upProcess);
        return Result.success(upProcess.getId());
    }

    @ApiOperation(value = "审批流 -编辑")
    @PutMapping()
    public Object edit(@RequestBody UpProcess upProcess){
    if (upProcess==null||upProcess.getId() == null)
       return Result.fail("id不能为空");
       return upProcessService.updateById(upProcess);
    }
}
